<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>评估单基础信息列表</title>
		<link rel="stylesheet" type="text/css" href="../lib/layui/css/layui.css" />

	</head>
	<body>
		<!-- 标题 -->
		<div class="title">
			<div class="back">
				<span class="layui-icon layui-icon-left"></span>
				<div class="layui-form">
					<div class="layui-form-item">
						<label class="layui-form-label">状态:</label>
						<div class="layui-input-block">
							<select name="interest">
								<option value="1">01床-张三</option>
								<option value="2">02床-李四</option>
								<option value="2">03床-王五</option>
							</select>
						</div>
					</div>
				</div>
				<div class="cent">
					001床-张丽丽&nbsp;&nbsp;&nbsp;&nbsp;住院号：0003902（1）
				</div>
				<button type="button">添加</button>
			</div>
		</div>

		<!-- 评估单选项卡 -->
		<div class="layui-tab layui-tab-brief" lay-filter="demo">
			<ul class="layui-tab-title">
				<li value="1">出入院护理评估单</li>
				<li class="layui-this" value="2">压疮风险评估</li>
				<li value="3">跌倒坠床评估单</li>
				<li value="4">疼痛评估单</li>
			</ul>
		</div>

		<!-- 表格 -->
		<table id="demo" lay-filter="test"></table>
		
		<!-- 分页 -->
		<div id="test2"></div>
		
		<script type="text/html" id="titleTpl">
			<a href="#" class="layui-table-link">编辑</a>
			<a href="#" class="layui-table-link">删除</a>
			<a href="#" class="layui-table-link">打印</a>
		</script>
	</body>
	<script src="../js/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
	<script src="../js/global.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		layui.use(['laypage', 'form', 'element', 'table', 'laytpl'], function() {
			var laytpl = layui.laytpl;
			var element = layui.element;
			var laypage = layui.laypage;
			var form = layui.form;
			var table = layui.table;

			// 默认参数
			var tpl = "2",
			page = "1",
			ptid = "100108597"
			
			// 监听tab
			element.on('tab(demo)', function(data) {
				console.log(data);
				var d = data.elem.prevObject.prevObject[0].value
				console.log(d);
				tpl = d;
				evalutionlist(tpl,page,ptid) 
			});


			//监听submit
			// form.on('submit(findhz)', function(data) {
			// 	console.log(data.field);
			// 	return false;
			// });
			
			
			
			function evalutionlist(tpl,page,ptid) {
				// 请求参数
				var param = JSON.stringify({
					"body": {
						"patientId": ptid,
						"templateId": tpl,
						 "currPage": page,
					},
					"header": {},
					"token": {}
				});
				$.ajax({
					'type': 'post',
					'url': '/service-nursing/evalution/list',
					'data': param,
					'dataType': 'json',
					'contentType': "application/json",
					'success': function(data) {
						console.log(data);
						var len = data.data.total;
						// var list = data.data.list;

						//表格
						table.render({
							elem: '#demo',
							height: 315,
							// toolbar: '#toolbarDemo',
							// page: true, //一次请求全部数据前端自动分页
							cols: [
								[{field:'insertTime',title:'时间',width:150},
								{field:'diatag',title:'入院诊断',width:150},
								{field:'total',title:'评估结果',width:150},
								{field:'resultStr',title:'结果提示',width:150},
								{field:'signNurse',title:'签名',width:150},
								{field:'title',title:'文章标题',width:200,templet:'#titleTpl'}]
							],
							data: data.data.list
						});
						// 分页
						laypage.render({
							elem: 'test2',
							count: len, //数据总数，从服务端得到
							curr: 1, //起始页
							// groups: 5,
							limit: 10,
							limits: [10],
							layout: ['count', 'prev', 'page', 'next', 'limit', 'skip'],
							jump: function(obj, first) {
								//obj包含了当前分页的所有参数，比如：
								console.log("当前页码" + obj.curr); //得到当前页，以便向服务端请求对应页的数据。
								console.log("当前显示" + obj.limit + "条"); //得到每页显示的条数
								//根据当前页请求和渲染模
								page = obj.curr
								//首次不执行
								if (!first) {
									evalutionlist(tpl,page,ptid) 
								}
							}
						});
					},
					'error': function(res) {
						console.log(res);
					}
				});
			}
			evalutionlist(tpl,page,ptid) ;
		})
	</script>
</html>
